package com.vstudy.zx.controller;

import com.vstudy.zx.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    private SearchService service;

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public String search(String key, Model model) {
        model.addAttribute("key", key);
        return "search.jsp";
    }

    @RequestMapping(value = "/search/searchArticle", method = RequestMethod.POST)
    @ResponseBody
    public Object searchArticle(String key, HttpServletRequest request) {
        return service.getArticles(key, request);
    }

    @RequestMapping(value = "/search/searchOutlines", method = RequestMethod.POST)
    @ResponseBody
    public Object searchOutlines(String key) {
        return service.getOutlines(key);
    }

    @RequestMapping(value = "/search/searchTeacher", method = RequestMethod.POST)
    @ResponseBody
    public Object searchTeacher(String key) {
        return service.getTeachers(key);
    }

    @RequestMapping(value = "/search/searchStudents", method = RequestMethod.POST)
    @ResponseBody
    public Object searchStudents(String key) {
        return service.getStudents(key);
    }
}
